#!/bin/bash

: ${1?"Not enough arguments: `basename $0` filter-regex-of-files-GONE-in-project
F.e. filter may be like: '^SPECS/zram.spec$', or just: 'zram' if you want simple match in any part of path.
This is opposite to git.filter!"}

# http://stackoverflow.com/questions/5998987/splitting-a-set-of-files-within-a-git-repo-into-their-own-repository-preserving
git filter-branch -f \
    --prune-empty \
    --index-filter '
        git ls-tree -z -r --name-only --full-tree $GIT_COMMIT \
        | egrep -z "'$1'" \
        | xargs -0 -r git rm --cached -r
    ' \
    -- \
    --all
